import React, { Component, PropTypes } from 'react';

import '../BodyDataInput.scss';
import LayoutView, { LayoutMode } from '../../layout';
import { SelectButtonGroup, SelectButton } from '../../common-ui-parts';
import { BodyItemConstant as BiC } from '../../../constants/InputItemConstants';
import { BodyDataInputContextConstant } from '../../../constants/ComponentContextConstants';

// 質問に関するイラスト
import imgQ15 from './images/imgQ15.png';

/**
 * Q15.慢性胃炎
 */
class Question15 extends Component {
  getChildContext() {
    const { [BiC.CHRONIC_GASTRITIS_FLG]: gastritis } = this.context.parent.inputData;
    return Object.freeze({
      parent: Object.freeze(Object.assign({}, this.context.parent, {
        // 未入力の場合、[入力完了]ボタンは無効
        disabledNext: gastritis === undefined,
      })),
    });
  }

  shouldComponentUpdate(nextProps, nextState) {
    return this.context.parent.pageIndex === nextProps.index;
  }

  scrollPageTop() {
    this.refs.layoutView.getWrappedInstance().scrollTop();
  }

  validatePage() {
    // 入力チェック（true:チェックOK）
    return this.context.parent.validateQuestionPage([BiC.CHRONIC_GASTRITIS_FLG]);
  }

  render() {
    const { inputData, errorInfo, updateState, handleSave } = this.context.parent;
    return (
      <LayoutView
        ref="layoutView"
        mode={LayoutMode.QUESTION}
        title="慢性胃炎"
        labelNext="入力完了"
        handleNext={handleSave}
        question={{
          no: 15,
          sentence: <p>血中のペプシノーゲンの測定で<br/>慢性胃炎があると<br/>言われたことがありますか？</p>,
          illustSrc: imgQ15,
          illustHeight: 188,
        }}
        errorText={errorInfo.get(BiC.CHRONIC_GASTRITIS_FLG) || errorInfo.all()}
      >
        {/* 慢性胃炎 */}
        <dl className="content">
          <dt style={{ display: 'none' }}>{BiC.CHRONIC_GASTRITIS_FLG.label}</dt>
          <dd>
            <SelectButtonGroup
              name={BiC.CHRONIC_GASTRITIS_FLG}
              value={inputData[BiC.CHRONIC_GASTRITIS_FLG]}
              propagate={updateState}
            >
              {BiC.CHRONIC_GASTRITIS_FLG.choices.map((choice, index) => (
                <SelectButton key={index} value={choice.value} label={choice.label} />
              ))}
            </SelectButtonGroup>
          </dd>
        </dl>
      </LayoutView>
    );
  }

}

Question15.contextTypes = BodyDataInputContextConstant;
Question15.childContextTypes = Question15.contextTypes;

/*Question15.propTypes = {
  index: PropTypes.number,    // 自ページINDEX（0～）
};*/

export default Question15
